$(document)
		.ready(
				function(){
					
					selectDiseaseControl();
					
});

function selectDiseaseControl(){
	// 遍历添加事件
	 $.each($("input[id^=diseaseFormControl]"),function(i,item) {
						$(item)
								.keyup(function(event) {
									var selectId = $(item).attr("id");
									var selectRealId = "";
									// 获取后面的id
									if (selectId.indexOf("-") != -1) {
										selectRealId = selectId.split("-")[1];
									}
									var jq_search_suggest = $("#search_suggest"
											+ selectRealId);
									var pinyinReg = /^[a-zA-Z]*$/;
									var bianhaoReg = /^[a-zA-Z]\d*.?\d*$/;
									var bianhaoReg2 = /^\d*.?\d*$/;
									var getVal = item.value;
									if (getVal
											&& getVal.length > 1) {
										var type = 4;
										if (pinyinReg
												.exec(getVal)) {
											// 拼音的时候
											type = 1;
											getVal = getVal
													.toUpperCase();
										} else if (bianhaoReg
												.exec(getVal)
												|| bianhaoReg2
														.exec(getVal)) {
											// 编号时
											getVal = getVal
													.toUpperCase();
											type = 3;
										} else {
											// 其他情况
											type = 2;
										}
										// 获取诊断类型
										/*var zdlx = $(
												"#idzdtype-"
														+ selectRealId
														+ " option:selected")
												.val();
										if (!zdlx) {
											zdlx = $(
													"#getzdtypeForGuDing"
															+ selectRealId)
													.val();
										}
										if (!zdlx) {
											alert("请选择诊断类型");
											return;
										}*/
										// ///////病理号
										/*if (zdlx == 44
												&& getVal
														.indexOf('M') != -1) {
											var bingliInputId = "#bingliInputVal-"
													+ selectRealId;
											var bingliDivId = "#bingliDiv-"
													+ selectRealId;
											var jq_binglidiv = $(bingliDivId);
											jq_binglidiv
													.empty();
											createBingliHaoInput(
													selectRealId)
													.appendTo(
															jq_binglidiv);

										}*/
										if (getVal.length > 1) {
											$
													.post(
															'../baseinfo/queryDisease',
															{
																queryValueType : type,
																queryValue : getVal
															},
															function(
																	data) {
																if (typeof (data) == "string") {
																	alert(data);
																	return false;
																}
																jq_search_suggest
																		.empty();
																xunhuanZiDian2(
																		data,
																		jq_search_suggest);
																// /////////////////////////////////////下按事件

																jq_search_suggest
																		.addClass(
																				"divscroll300 search_suggest")
																		.show();
																$("#getjbzdbm-"+ selectRealId).val("");
																$("#getjbmc-"+ selectRealId).val("");
															},
															'json');
										} else {
											$("#getjbzdbm-"+ selectRealId).val("");
											$("#getjbmc-"+ selectRealId).val("");
											jq_search_suggest.hide();
										}
									} else {
										$("#getjbzdbm-"+ selectRealId).val("");
										$("#getjbmc-"+ selectRealId).val("");
										jq_search_suggest.hide();
									}
									function xunhuanZiDian2(
											data, com) {
										com.empty();
										
										var rowNum = 1;
										for ( var index in data) {
											var Obj = data[index];
											var code = Obj.code;
											var name = Obj.name;
											
											var opt = $("<div>").attr('code',code).attr('name',name).text(code+ "-"+ name).addClass("suggest_link");
											opt.mouseover(
															function() {
																var divOpts = $("div[rowNum][ck='ck']");
																divOpts
																		.attr(
																				"ck",
																				"");
																$(
																		this)
																		.addClass(
																				"suggest_link_over")
																		.attr(
																				"ck",
																				"ck");

															})
													.mouseout(
															function() {
																$(
																		"div[rowNum][ck]")
																		.removeClass(
																				"suggest_link_over");
																;
																$(
																		this)
																		.removeClass(
																				"suggest_link_over");
																$(
																		this)
																		.addClass(
																				"suggest_link");
															})
													.click(
															function() {
																var zhuyaozhenduanError = new Array();
																// 获取值
																var selectDivObj = $(this);
																var code = selectDivObj
																		.attr("code");
																var diaeaseName = selectDivObj.attr("name");
																var text = selectDivObj
																		.text();
																
																// 赋值
																$("#getjbzdbm-"+ selectRealId).val(code);
																$("#getjbmc-"+ selectRealId).val(diaeaseName);
																$(
																		"#diseaseFormControl-"
																				+ selectRealId)
																		.val(
																				text);
																$(
																		"#diseaseFormControl-"
																				+ selectRealId)
																		.focus();
																
																
																// //////////////判断逻辑end////////////////
																
																
																// 隐藏显示层
																jq_search_suggest
																		.hide();
															});
											com.append(opt);
										}
									}
								});
						// ////////////////////////////编码制空---------2014-01-24
						$(item)
								.blur(function() {
									var thisInput = $(this);
									var shiVal = thisInput
											.val();
								});
					});
	// ///////////////////////////////////////////////////////////////////
	// 新增一行
/*	$("#addnewid")
			.click(
					function() {
						var yishiStateVal = $("#yishiState")
								.val();
						if (yishiStateVal) {
							window.location.href = "bingan/addNewRow?getType=1";
						} else {
							window.location.href = "bingan/addNewRow";
						}
					});
	$("#lczdid")
	.click(
			function() {
				var yishiStateVal = $("#yishiState")
						.val();
				if (yishiStateVal) {
					window.location.href = "bingan/lcsjtb";
				} else {
					window.location.href = "bingan/lcsjtb";
				}
			});
	$("#zongAdd").click(function() {
		handlerZongAdd();
	});
	

	function handlerZongAdd() {
		$
				.post(
						'bingan/checkJBZDError',
						{

						},
						function(data) {
							var errMsg = data.err;
							if (errMsg == 1) {
								var yishiStateVal = $(
										"#yishiState").val();
								if (yishiStateVal) {
									var myDate = new Date();
									window.location.href = "bingan/addzdjb?getType=1&d="
											+ myDate
													.getMilliseconds();
								} else {
									var myDate = new Date();
									window.location.href = "bingan/addzdjb?d="
											+ myDate
													.getMilliseconds();
								}
							} else {
								showDiv(errMsg);
							}
						}, 'json');

	}*/

}

/*function updatezdbingqing(selectRealId) {
	$.post('bingan/updateZDData', {
		"updateZiDuan" : "idzdrybq",
		"updateData" : "1",
		"updateid" : selectRealId
	}, function(data) {
		$("#idzdrybq-" + selectRealId).val("1");
	}, 'json');
};
function getFirstCiYao() {
	var ciyaos = $("select[id^=idzdtype-]");
	var cyzdVal = "";
	ciyaos.each(function() {
		var jq_this = $(this);
		var typeVal = jq_this.val();
		var thisrealId = jq_this.attr("id").split("-")[1];
		if (typeVal == 23) {
			cyzdVal = $("#jiansuojibing-" + thisrealId).val();
			var bm = cyzdVal.split("--")[0];
			var bmName = cyzdVal.split("--")[1];
			if (bm && bmName) {
				return false;
			}
		}
	});
	if (cyzdVal) {
		return cyzdVal;
	}
	var cyhanzi = $("input[id^=getzdtypeForGuDing]");
	cyhanzi.each(function() {
		var jq_this = $(this);
		var typeVal = jq_this.val();
		var thisrealId = jq_this.attr("id").split("GuDing")[1];
		if (typeVal == 23) {
			cyzdVal = $("#jiansuojibing-" + thisrealId).val();
			if (cyzdVal) {
				var bm = cyzdVal.split("--")[0];
				var bmName = cyzdVal.split("--")[1];
				if (bm && bmName) {
					return false;
				}
			}
		}
	});
	return cyzdVal;
}*/


function changeTreatment(isTreatment){
		var selectId = $(isTreatment).attr("id");
		var selectRealId = "";
		if (selectId.indexOf("-") != -1) {
			selectRealId = selectId.split("-")[1];
		}
		 var submitTreament = $("input[name='hospitalizationDiagnosis["+selectRealId+"].treatment']");
	        var checked = $(isTreatment).prop('checked');
	        if (checked) {
	        	submitTreament.val("true");
	        }else {
	        	submitTreament.val("false");
	        }
}